package net.pulseproject.router.config.instantiator.builder;

import java.util.Collection;

import net.pulseproject.commons.midi.Receivable;
import net.pulseproject.commons.midi.entity.MidiSocket;
import net.pulseproject.router.config.instantiator.builder.validator.FieldValidator;
import net.pulseproject.router.config.instantiator.builder.validator.SkeletonFieldValidator;
import net.pulseproject.router.modules.useable.MidiTransmitterModule;

public class MidiTransmitterModuleBuilder extends MidiModuleBuilder<MidiTransmitterModule> {

	private Collection<Receivable> outgoingModules;

	private final FieldValidator validator = new SkeletonFieldValidator() {
		@SuppressWarnings("synthetic-access")
		@Override
		protected void validateFields() {
			if(MidiTransmitterModuleBuilder.this.outgoingModules == null) {
				throw new RuntimeException("outgoingModules not yet set");
			}
		}
	};
	
	public MidiTransmitterModuleBuilder() {
		this.addValidator(this.validator);
	}
	
	public final void setOutgoingModules(final Collection<Receivable> outgoingModules) {
		this.outgoingModules = outgoingModules;
	}
	
	@Override
	protected final MidiTransmitterModule buildModule() {
		final MidiSocket socket = new MidiSocket(this.getPort(), this.getChannel(), this.getController());
		return new MidiTransmitterModule(this.getId(), socket, this.outgoingModules);
	}

}
